require 'rubygems'
require 'pp'
# p = [{8=>2}, {81=>28}, {8=>1}, {81=>3}, {2=>1}, {15=>2}, {16=>6}, {10=>4}, {2=>1}, {3=>2}, {11=>5}, {12=>6}, {13=>3}, {7=>3}, {14=>3}, {9=>30}, {27=>20}, {2=>10}, {52=>15}, {74=>52}, {96=>20}, {20=>20}, {23=>15}, {35=>10}]
p = [{8=>2}, {8=>28},{1 => 2},{1 => 3}]


h1 = {}

products_array = Inproduct.all(:conditions => {:f_store_id => 1}).map{|p| {p.product_id => p.amount}}

def count_products_by_store(source_array)
  result = {}
  source_array.each do |h|
    key = h.keys.first
    value = h.values.first
    unless result.has_key?(key)
      result[key] = value
    else
      result[key] = result[key] + value
    end
  end
  return result
end


pp h1